﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

namespace PreDesignCard
{
    public partial class Popup : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ShowReport();
            }
        }
        public void ShowReport()
        {
            string lastname = Request.QueryString["txtName"];
            string firstname = Request.QueryString["txtFirstName"];
            string GCNumber = Request.QueryString["txtGCNumber"];
            string GCV = Request.QueryString["txtGCV"];
            string store = Request.QueryString["txtStore"];
            ReportDocument cryRpt = new ReportDocument();
            

            cryRpt.Load(Server.MapPath("CrystalReport1.rpt"));

            CrystalReportViewer1.ReportSource = cryRpt;
            char[] a = lastname.ToCharArray();
            char[] b = firstname.ToCharArray();
            char[] c = GCNumber.ToCharArray();
            char[] d = GCV.ToCharArray();
            char[] s = store.ToCharArray();
            for (int i = 0; i < 15; i++)
            {
                string param = "N" + (i + 1).ToString();
                if(i < a.Length) cryRpt.SetParameterValue(param, a[i].ToString());
                else cryRpt.SetParameterValue(param, "");
            }
            for (int i = 0; i < 15; i++)
            {
                string param = "F" + (i + 1).ToString();
                if (i < b.Length) cryRpt.SetParameterValue(param, b[i].ToString());
                else cryRpt.SetParameterValue(param, "");
            }
            for (int i = 0; i < 14; i++)
            {
                string param = "G" + (i + 1).ToString();
                if (i < c.Length) cryRpt.SetParameterValue(param, c[i].ToString());
                else cryRpt.SetParameterValue(param, "");
            }
            for (int i = 0; i < 10; i++)
            {
                string param = "V" + (i + 1).ToString();
                if (i < d.Length) cryRpt.SetParameterValue(param, d[i].ToString());
                else cryRpt.SetParameterValue(param, "");
            }
            for (int i = 0; i < 15; i++)
            {
                string param = "S" + (i + 1).ToString();
                if (i < s.Length) cryRpt.SetParameterValue(param, s[i].ToString());
                else cryRpt.SetParameterValue(param, "");
            }
           // CrystalReportViewer1.RefreshReport();
            //CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;

            //PageMargins margins;
            ////ReportDocument rpt = new ReportDocument();
            //margins = cryRpt.PrintOptions.PageMargins;
            //margins.bottomMargin = 350;
            //margins.leftMargin = 350;
            //margins.rightMargin = 350;
            //margins.topMargin = 350;
            //cryRpt.PrintOptions.ApplyPageMargins(margins);

            //cryRpt.PrintOptions.PrinterName = "HP LaserJet 400 M401 PCL 6";
            //System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
            //cryRpt.PrintOptions.PrinterName = printDocument.PrinterSettings.PrinterName;

            //cryRpt.PrintToPrinter(1, false, 0, 0);
        }

        
    }
}
